<template>
    <el-card class="box-card">
        <div slot="header" class="clearfix">
            <span>登录</span>
        </div>

        <el-form
            :model="ruleForm"
            status-icon
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
        >
            <el-form-item label="用户名" prop="username">
                <el-input v-model="ruleForm.username"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="pwd">
                <el-input
                    type="password"
                    v-model="ruleForm.pwd"
                    autocomplete="off"
                ></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')"
                    >提交</el-button
                >
                <el-button @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
        </el-form>
    </el-card>
</template>

<script>
import { login } from "../services/user";
export default {
    data() {
        return {
            ruleForm: {
                username: "",
                pwd: "",
            },
        };
    },
    methods: {
        async submitForm(formName) {
            let data = await login(this.ruleForm);
            if (data.status == 1) {
                localStorage.setItem('token',data.token);
                this.$router.push("/manage");
            } else {
                this.$alert("登录失败", "提示", {
                    confirmButtonText: "确定",
                });
            }
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
    },
};
</script>

<style>
.box-card {
    width: 500px;
    margin: auto;
}
</style>